Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

369
Visualizações
Match "And" if the preceding sentence has an "and"

Basically, I want to do this:

Text and text text. Text text. And text. (Don't match this "And.")
Text and text text. And text. (Match this "And.")

Right now, I have this regex: .*\b(and)\b.*\. And. But it matches both And's in the example above: https://regexr.com/65k52

How to modify this regex so it only matches And if the previous sentence has and?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you want to use . + whitespace as a sentence separator sequence you can use

(?=\S)[^.]*(?:\.(?!\s)[^.]*)*?\band\b[^.]*(?:\.(?!\s)[^.]*)*\.\s+And\b
(?=\S)(?:[^.]|\.(?!\s))*?\band\b(?:[^.]|\.(?!\s))*\.\s+And\b

See the regex demo #1 and regex demo #2. Details:

  • (?=\S) - next char must be a non-whitespace
  • (?:[^.]|\.(?!\s))*? - zero or more (but as few as possible) occurrences of any one char other than . or a . that is not immediately followed with whitespace
  • \band\b - whole word and
  • (?:[^.]|\.(?!\s))* - zero or more (but as many as possible) occurrences of any one char other than . or a . that is not immediately followed with whitespace
  • \. - a dot
  • \s+ - one or more whitespaces
  • And\b - a whole word And.
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda